<?php
namespace BoxEdu\Controller\Home;
class CommonController extends \HomeController
{
    public function _initialize()
    {
        parent::_initialize();
        \Think\Hook::listen('BoxEdu_begin');//
        $this->nav_cur = "Home";
        $this->class_list = BoxModel("EduSubject")->class_list();
        $this->header_nav = "Public:header";
        $this->public_header = "Public:head";
        $this->web_title = "考试突击";
        $this->setCookie();
        //echo $_SERVER['HTTP_USER_AGENT'];
        //	dump($this->user_info);
        //echo md5('123456');exit();
        // $this->getHeader();
        //dump($this->user_info);exit();
    }

    public function setCookie()
    {
        if ($this->is_mobile) {
            Logic("BoxSns", "Member")->set_login();
        }
    }

    public function getHeader()
    {
        $header = "./Apps/" . C('DEFAULT_MODULE') . "/View/Home/Public/head_cache.html";
        $headerReal = "./Apps/" . C('DEFAULT_MODULE') . "/View/Home/Public/head.html";
        if (APP_DEBUG === true) {
            $this->resCache($headerReal);
            $this->public_header = "Public:head_cache";
        } else {
            if (!is_file($header)) {
                $this->resCache($headerReal);
            }
            $this->public_header = "Public:head";
        }
    }

    public function ckeck_students_info()
    {
        if (ACTION_NAME != "students_info" && ACTION_NAME != "get_ajax_school_sel") {
            $r = BoxModel("edu_students")->where("user_id='$this->user_id'")->find();
            if (!$r['school_id']) {
                $this->jump("", U("User/students_info"));
            }
        }
    }


    /****display模板***/
    public function display($dir)
    {
        if (!is_file($dir)) {
            $templateFile = $this->getTemplateFile("Index/home");
            $this->page_content = self::fetch($dir);
            if (IS_AJAX || I('requestFrom') == 'modal') {
                echo $this->page_content;
            } else {
                parent::display($templateFile);
            }
        } else {
            parent::display($dir);
        }
    }

    public function getTemplateFile($templateFile)
    {

        //dump( $this->is_mobile);
        $tpl = BOX_MODULE_NAME;
        if ($this->is_mobile) {
            $tpl = "Wap";
        }
        if (!checkAgent()) {
            $tpl = "Wap";
        }
        C('DEFAULT_V_LAYER', "View/" . $tpl);
        if ($templateFile == "" || !is_file($templateFile)) {
            $depr = C('TMPL_FILE_DEPR');
            if (!$templateFile) {
                $templateFile = CONTROLLER_NAME . $depr . ACTION_NAME;
            }
        }
        $File = "./Apps/" . C('DEFAULT_MODULE') . "/View/" . $tpl . "/" . $templateFile . C('TMPL_TEMPLATE_SUFFIX');
        if ($tpl != "Home" && is_file($File)) {
            return $File;
        } else {
            return "./Apps/" . C('DEFAULT_MODULE') . "/View/Home/" . $templateFile . C('TMPL_TEMPLATE_SUFFIX');
        }

    }

    /****fetch模板***/
    public function fetch($templateFile, $content = '', $prefix = '')
    {
        $templateFile = $this->getTemplateFile($templateFile);
        return parent::fetch($templateFile, $content, $prefix);
    }


    /*****用户中心页面***/
    function show_user($page)
    {
        $templateFile = $this->getTemplateFile("Index/home");
        $this->user_page_content = self::fetch($page);
        if (IS_AJAX && I('requestFrom') == 'modal') {
            echo $this->user_page_content;
        } else {
            $this->page_content = self::fetch("User/index");
            parent::display($templateFile);
        }
    }


}

 